﻿@using System.Data;
@using System.Web;
@using DTcms.Web.MVC.Areas.Web.Controllers;
@using DTcms.Web.MVC.UI.Controllers;
@using DTcms.Model;
@{
   Layout = "~/Areas/Web/Views/" + ViewBag.TemplateSkin + "/Shared/_LayoutShow.cshtml";
   DTcms.Model.sites site = ViewData["site"] as DTcms.Model.sites;
   DTcms.Model.sysconfig config = ViewData["sysConfig"] as DTcms.Model.sysconfig;
   BaseController bc = ViewBag.BasePage as BaseController;
   UserAmountController c = ViewBag.This as UserAmountController;
   DTcms.Model.users m = c.userModel;
   ViewBag.Title = "账户余额 - " + site.name;
   string action = ViewBag.Action as string;
   int totalcount = 0;
   int page = int.Parse(ViewBag.Page as string);
   string pageList = string.Empty;
   
}
@section HeaderContent{
   @switch(action){
      case "recharge":
         <script type="text/javascript" src="@(config.webpath)scripts/jquery/jquery.form.min.js"></script>
         <script>
            $(function () {
               //初始化表单
               AjaxInitForm('#rechargeForm', '#btnSubmit', 0);
            });
         </script>         
         break;
      case "log":
         <script>
            function ExecPostBack(checkValue) {
               if (arguments.length == 1) {
                  ExecDelete('@(config.webpath)tools/submit_ajax.ashx?action=user_recharge_delete', checkValue, '#turl');
               } else {
                  var valueArr = '';
                  $("input[name='checkId']:checked").each(function (i) {
                     valueArr += $(this).val();
                     if (i < $("input[name='checkId']:checked").length - 1) {
                        valueArr += ","
                     }
                  });
                  ExecDelete('@(config.webpath)tools/submit_ajax.ashx?action=user_recharge_delete', valueArr, '#turl');
               }
            }
	     </script>      
      break;
      case "list":
         <script type="text/javascript">
            function ExecPostBack(checkValue) {
               if (arguments.length == 1) {
                  ExecDelete('@(config.webpath)tools/submit_ajax.ashx?action=user_amount_delete', checkValue, '#turl');
               } else {
                  var valueArr = '';
                  $("input[name='checkId']:checked").each(function (i) {
                     valueArr += $(this).val();
                     if (i < $("input[name='checkId']:checked").length - 1) {
                        valueArr += ","
                     }
                  });
                  ExecDelete('@(config.webpath)tools/submit_ajax.ashx?action=user_amount_delete', valueArr, '#turl');
               }
            }
	     </script>      
      break;
   }
}

<!--当前位置-->
<div class="section">
  <div class="location">
    <span>当前位置：</span>
    <a href="@bc.linkurl("index")">首页</a> &gt;
        <a href="@bc.linkurl("usercenter", "index")">会员中心</a>
    <a href="@bc.linkurl("useramount", "list")">账户余额</a>
  </div>
</div>
<!--/当前位置-->

<div class="section clearfix">
  <!--左侧导航-->
  @RenderPage("~/Areas/Web/Views/" + ViewBag.TemplateSkin + "/Shared/partial_ucenter_nav.cshtml")
  <!--/左侧导航-->

  <!--右侧内容-->
  <div class="right-auto">
    <div class="bg-wrap" style="min-height: 765px;">
      @if (action == "recharge") {
        <!--账户充值-->
        <div class="sub-tit">
          <a class="add" href="javascript:history.go(-1);"><i class="iconfont icon-reply"></i>返回</a>
          <ul>
            <li class="selected">
              <a href="@bc.linkurl("useramount", "recharge")">账户充值</a>
            </li>
            <li>
              <a href="@bc.linkurl("useramount", "log")">充值记录</a>
            </li>
            <li>
              <a href="@bc.linkurl("useramount", "list")">收支明细</a>
            </li>
          </ul>
        </div>

        <form id="rechargeForm" name="recharge_form" url="@(config.webpath)tools/submit_ajax.ashx?action=user_amount_recharge&site_id=@site.id">
          <div class="form-box">
            <dl class="form-group">
              <dt>账户余额：</dt>
              <dd>当前账户金额为：<b class="red">￥@m.amount</b> 元</dd>
            </dl>
            <dl class="form-group">
              <dt>充值金额：</dt>
              <dd>
                <input name="order_amount" id="order_amount" type="text" class="input small" onkeydown="return checkNumber(event);" datatype="n" nullmsg="请输入金额" sucmsg=" " />
                元
              </dd>
            </dl>
            <dl class="form-group">
              <dt>支付方式：</dt>
              <dd>
                @{ DataTable payList = bc.get_payment_list(0, "type=1 and payment_id>2 and site_id=" + site.id); }
                @for (int i = 0; i < payList.Rows.Count; i++) {
                  DataRow dr = payList.Rows[i];
                  if (i == payList.Rows.Count - 1) {
                  <label class="mart">
                    <input name="payment_id" type="radio" value="@dr["id"]" datatype="*" sucmsg=" " />
                    @dr["title"]</label>
               }
               else {
                  <label class="mart">
                    <input name="payment_id" type="radio" value="@dr["id"]" />
                    @dr["title"]</label>
               }
                }
              </dd>
            </dl>
            <dl class="form-group">
              <dd>
                <input name="btnSubmit" id="btnSubmit" type="submit" class="submit" value="确认充值" /></dd>
            </dl>
          </div>
        </form>

        <!--/账户充值-->
      }
      else if (action == "log") {
        <!--充值记录-->
        <div class="sub-tit">
          <a class="add" href="javascript:history.go(-1);"><i class="iconfont icon-reply"></i>返回</a>
          <ul>
            <li>
              <a href="@bc.linkurl("useramount", "recharge")">账户充值</a>
            </li>
            <li class="selected">
              <a href="@bc.linkurl("useramount", "log")">充值记录</a>
            </li>
            <li>
              <a href="@bc.linkurl("useramount", "list")">收支明细</a>
            </li>
          </ul>
        </div>
        <div class="table-wrap">
          <table width="100%" border="0" cellspacing="0" cellpadding="0" class="mtable">
            @{ 
        DataTable rechargeList = bc.get_user_recharge_list(10, page, "user_id=" + m.id, out totalcount);
        pageList = bc.get_page_link(10, page, totalcount, "useramount", action, "__id__");<!--取得分页页码列表-->
            }
            @foreach (DataRow dr in rechargeList.Rows) {
              <tr>
                <td width="20" align="center">
                  <input name="checkId" class="checkall" type="checkbox" value="@dr["id"]" >
                </td>
                <td>@dr["add_time"]</td>
                <td width="140">@dr["recharge_no"]</td>
                <td width="80">@c.get_payment_title(Convert.ToInt32(dr["payment_id"]))</td>
                <td width="80">￥@dr["amount"]</td>
                <td width="50">@(Convert.ToInt32(dr["status"]) > 0 ? "已完成" : "未完成")</td>
                <td width="30"><a onclick="ExecPostBack('@dr["id"]');" href="javascript:;">删除</a></td>
              </tr>
            }
            @if (rechargeList.Rows.Count == 0) {
              <tr>
                <td colspan="5" align="center">暂无记录...</td>
              </tr>
            }
          </table>
          <div class="page-foot">
            <div class="flickr right">@Html.Raw(pageList)</div>
            <!--放置页码列表-->
            <div class="btn-box">
              <a onclick="checkAll(this);" href="javascript:;">全选</a>
              <a onclick="ExecPostBack();" href="javascript:;">删除</a>
            </div>
          </div>
        </div>
        <input id="turl" type="hidden" value="@bc.linkurl("useramount", "log")" /><!--存在跳转的URL值-->
        <!--/充值记录-->
      }
      else if (action == "list") {
        <!--收支明细-->
        <div class="sub-tit">
          <a class="add" href="javascript:history.go(-1);"><i class="iconfont icon-reply"></i>返回</a>
          <ul>
            <li>
              <a href="@bc.linkurl("useramount", "recharge")">账户充值</a>
            </li>
            <li>
              <a href="@bc.linkurl("useramount", "log")">充值记录</a>
            </li>
            <li class="selected">
              <a href="@bc.linkurl("useramount", "list")">收支明细</a>
            </li>
          </ul>
        </div>
        <div class="table-wrap">
          <table width="100%" border="0" cellspacing="0" cellpadding="0" class="mtable">
            @{
        DataTable amountList = bc.get_user_amount_list(10, page, "user_id=" + m.id, out totalcount); <!--取得一个DataTable-->
        pageList = bc.get_page_link(10, page, totalcount, "useramount", action, "__id__"); <!--取得分页页码列表-->
            }
            @foreach (DataRow dr in amountList.Rows) {
              <tr>
                <td width="20" align="center">
                  <input name="checkId" class="checkall" type="checkbox" value="@dr["id"]" >
                </td>
                <td width="150">@dr["add_time"]</td>
                <td>@dr["remark"]</td>
                <td width="50">@(Convert.ToInt32(dr["value"]) > 0 ? "+" + dr["value"].ToString() : dr["value"])</td>
                <td width="30"><a onclick="ExecPostBack('@dr["id"]');" href="javascript:;">删除</a></td>
              </tr>
            }
            @if (amountList.Rows.Count == 0) {
              <tr>
                <td colspan="5" align="center">暂无记录...</td>
              </tr>
            }
          </table>
          <div class="page-foot">
            <div class="flickr right">@Html.Raw(pageList)</div>
            <!--放置页码列表-->
            <div class="btn-box">
              <a onclick="checkAll(this);" href="javascript:;">全选</a>
              <a onclick="ExecPostBack();" href="javascript:;">删除</a>
            </div>
          </div>
        </div>
        <input id="turl" type="hidden" value="@bc.linkurl("useramount", "list")" /><!--存在跳转的URL值-->
        <!--收支明细-->
      }
    </div>
  </div>
  <!--/右侧内容-->
</div>
